<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>for-in</title>
</head>

<body>

</body>
<script>
    //for-in得到的都是key
    var student = { name: 'tom', age: '23', sex: '男' };
    for (let item in student) {
        console.log(item, student[item]);
        //name tom
        //age 23
        //sex 男
    }

    //遍历装对象的数组
    var arr = [{ name: 'tom', age: '18' }, { name: 'jerry', age: '19' }, { name: 'rose', age: '17' }];
    for (let item in arr) {
        console.log(item, arr[item], arr[item].name, arr[item].age);
    }

    //遍历数组中的对象
    var students = [
        { name: '张三', age: 23 },
        { name: '李四', age: 24 },
        { name: '王二麻子', age: 35 }
    ]
    //自定义属性key为name，value是86期班的学生们
    students.name = "詹姆斯"
    for (let item of students) {
        console.log("打印forof对象：", item) 
    }
    //for-in会遍历自定义属性
    for (let item in students) {
        console.log("打印forin对象：", item, students[item])
    }

</script>

</html>